<?php
namespace app\admin\controller;
use common\util\Tools;
use app\common\model\GoodsCatModel;

class GoodsClassify extends Base {
    
    /*
     * 初始化操作
     */
    public function _initialize(){
        $this->needLogin();
        
    }

    // 产品分类列表
    public function index()
    {
        return $this->fetch();
    }
    
    public function rs(){
        $length = 10;
        $draw = $this->request->param('draw',1);
        $start = $this->request->param('start',0);
        
        $list = GoodsCatModel::instance()->limit($start,$length)->order('id','desc')->select();
        $count = GoodsCatModel::instance()->count();
        
        $data = array(
            "returnCode" => 1,
            "returnMsg" => "success!",
            'recordsTotal' => $count,
            'recordsFiltered' => $count,
            'draw' => $draw,
            'data' => $list
        );
        return json($data);
    }

    // 产品分类 | 添加
    public function add()
    {
        return $this->fetch();
    }

    public function add_post(){
        $data = $this->request->param();
        $data['type'] = 1;
        $data['addtime'] = Tools::getCurDate();
        $data['updatetime'] = Tools::getCurDate();
        $id = GoodsCatModel::instance()->insertGetId($data);
        return $this->returnResult(1,'添加成功');
    }
    // 产品分类 | 编辑
    public function edit()
    {
        $id = $this->request->param('id');
        $cate = GoodsCatModel::instance()->find($id);
        $this->assign('cate',$cate);
        return $this->fetch();
    }
    
    public function edit_post(){
        $data = $this->request->param();
        $data['updatetime'] = Tools::getCurDate();
        $id = GoodsCatModel::instance()->update($data);
        return $this->returnResult(1,'更新成功');
    }
    
    public function update(){
        $data = $this->request->param();
        $data['updatetime'] = Tools::getCurDate();
        $id = GoodsCatModel::instance()->update($data);
        return $this->returnResult(1,'更新成功');
    }

}
